package com.cy.springcloudalibaba.services;

import com.cy.springcloudalibaba.configs.FeignConfig;
import com.cy.springcloudalibaba.fallbacks.FeignFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Description: feign调用远程客户端
 * @ClassName: FeignService
 * @Author: chenyu
 * @Date: 2025/1/10 11:28
 */
@FeignClient(name = "01-nacos-discovery-provider",
             fallback = FeignFallback.class,
             configuration = FeignConfig.class)
public interface FeignService {

    /**
     *  声明一个方法，这个方法就是远程的服务提供者提供的那个方法
     */
    @GetMapping("/feign/{app}")
    String feign(@PathVariable("app") String app);

    @GetMapping("/feign/divide")
    String divide(@RequestParam("a") Integer a, @RequestParam("b") Integer b);

    @GetMapping("/feign/print")
    String print(@RequestParam("a") String a);

    /**
     *  feign声明的接口可以有默认实现，不需要远程服务提供实现
     */
    default String divide(Integer a) {
        System.out.println("consumer divide method......");
        return divide(a, 1);
    }
}
